
import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	public int compareTo(PersonSortable o){
		if(this.name.compareTo(o.name)==0){
			if(this.age==o.age)
				return 0;
			else if(this.age>o.age)
				return 1;
			else if(this.age<o.age)
				return -1;
		}
		return name.compareTo(o.name);
	}
	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
	}
	public String toString() {
		return name + "-" + age;
	}
}

public class Main1 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		PersonSortable[] person=new PersonSortable[n];
		for(int i=0;i<n;i++){
			person[i]=new PersonSortable(sc.next(),sc.nextInt());
		}
		Arrays.sort(person);
		for(int i=0;i<n;i++){
			System.out.println(person[i]);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}
}
